<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Using Kotlin</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/kotlin" />
  <meta property="og:title" content="Quarkus - Using Kotlin" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/kotlin">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Using Kotlin</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#prerequisites">Prerequisites</a></li>
<li><a href="#creating-the-maven-project">Creating the Maven project</a>
<ul class="sectlevel2">
<li><a href="#update-code">Update code</a></li>
</ul>
</li>
<li><a href="#important-maven-configuration-points">Important Maven configuration points</a></li>
<li><a href="#important-gradle-configuration-points">Important Gradle configuration points</a></li>
<li><a href="#cdi-inject-with-kotlin">CDI @Inject with Kotlin</a></li>
<li><a href="#live-reload">Live reload</a></li>
<li><a href="#packaging-the-application">Packaging the application</a></li>
<li><a href="#kotlin-and-jackson">Kotlin and Jackson</a></li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p><a href="https://kotlinlang.org/">Kotlin</a> is a very popular programming language that targets the JVM (amongst other environments). Kotlin has experienced a surge in popularity the last few years making it the most popular JVM language, except for Java of course.</p>
</div>
<div class="paragraph">
<p>Quarkus provides first class support for using Kotlin as will be explained in this guide.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>This technology is considered preview.</p>
</div>
<div class="paragraph">
<p>In <em>preview</em>, backward compatibility and presence in the ecosystem is not guaranteed.
Specific improvements might require to change configuration or APIs and plans to become <em>stable</em> are under way.
Feedback is welcome on our <a href="https://groups.google.com/d/forum/quarkus-dev">mailing list</a> or as issues in our <a href="https://github.com/quarkusio/quarkus/issues">GitHub issue tracker</a>.</p>
</div>
<div class="paragraph">
<p>For a full list of possible extension statuses, check our <a href="https://quarkus.io/faq/#extension-status">FAQ entry</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="prerequisites"><a class="anchor" href="#prerequisites"></a>Prerequisites</h2>
<div class="sectionbody">
<div class="paragraph">
<p>To complete this guide, you need:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>less than 10 minutes</p>
</li>
<li>
<p>an IDE</p>
</li>
<li>
<p>JDK 1.8+ installed with <code>JAVA_HOME</code> configured appropriately</p>
</li>
<li>
<p>Apache Maven 3.6.2+</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>NB: For Gradle project setup please see below, and for further reference consult the guide in the <a href="gradle-tooling">Gradle setup page</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="creating-the-maven-project"><a class="anchor" href="#creating-the-maven-project"></a>Creating the Maven project</h2>
<div class="sectionbody">
<div class="paragraph">
<p>First, we need a new Kotlin project. This can be done using the following command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="shell" class="language-shell hljs">mvn io.quarkus:quarkus-maven-plugin:1.7.0.Final:create \
    -DprojectGroupId=org.acme \
    -DprojectArtifactId=rest-kotlin-quickstart \
    -DclassName="org.acme.rest.GreetingResource" \
    -Dpath="/greeting" \
    -Dextensions="kotlin,resteasy-jsonb"
cd rest-kotlin-quickstart</code></pre>
</div>
</div>
<div class="paragraph">
<p>When adding <code>kotlin</code> to the extensions list, the Maven plugin will generate a project that is properly
configured to work with Kotlin. Furthermore  the <code>org.acme.rest.GreetingResource</code> class is implemented as Kotlin source code (as is the case with the generated tests).
The addition of <code>resteasy-jsonb</code> in the extension list results in importing the RESTEasy/JAX-RS and JSON-B extensions.</p>
</div>
<div class="paragraph">
<p><code>GreetingResource.kt</code> looks like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">package org.acme.rest

import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

@Path("/greeting")
class GreetingResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    fun hello() = "hello"
}</code></pre>
</div>
</div>
<div class="sect2">
<h3 id="update-code"><a class="anchor" href="#update-code"></a>Update code</h3>
<div class="paragraph">
<p>In order to show a more practical example of Kotlin usage we will add a simple <a href="https://kotlinlang.org/docs/reference/data-classes.html">data class</a> called <code>Greeting.kt</code> like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">package org.acme.rest

data class Greeting(val message: String = "")</code></pre>
</div>
</div>
<div class="paragraph">
<p>We also update the <code>GreetingResource.kt</code> like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType

@Path("/greeting")
class GreetingResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    fun hello() = Greeting("hello")
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>With these changes in place the <code>/greeting</code> endpoint will reply with a JSON object instead of a simple String.</p>
</div>
<div class="paragraph">
<p>To make the test pass, we also need to update <code>GreetingResourceTest.kt</code> like so:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">@QuarkusTest
class GreetingResourceTest {

    @Test
    fun testHelloEndpoint() {
        given()
          .`when`().get("/greeting")
          .then()
             .statusCode(200)
             .body("message", equalTo("hello"))
    }

}</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="important-maven-configuration-points"><a class="anchor" href="#important-maven-configuration-points"></a>Important Maven configuration points</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The generated <code>pom.xml</code> contains the following modifications compared to its counterpart when Kotlin is not selected:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The <code>quarkus-kotlin</code> artifact is added to the dependencies. This artifact provides support for Kotlin in the live reload mode (more about this later on)</p>
</li>
<li>
<p>The <code>kotlin-stdlib-jdk8</code> is also added as a dependency.</p>
</li>
<li>
<p>Maven&#8217;s <code>sourceDirectory</code> and <code>testSourceDirectory</code> build properties are configured to point to Kotlin sources (<code>src/main/kotlin</code> and <code>src/test/kotlin</code> respectively)</p>
</li>
<li>
<p>The <code>kotlin-maven-plugin</code> is configured as follows:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;plugin&gt;
    &lt;artifactId&gt;kotlin-maven-plugin&lt;/artifactId&gt;
    &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
    &lt;version&gt;${kotlin.version}&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;id&gt;compile&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;compile&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
        &lt;execution&gt;
            &lt;id&gt;test-compile&lt;/id&gt;
            &lt;goals&gt;
                &lt;goal&gt;test-compile&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
    &lt;configuration&gt;
        &lt;compilerPlugins&gt;
            &lt;plugin&gt;all-open&lt;/plugin&gt;
        &lt;/compilerPlugins&gt;

        &lt;pluginOptions&gt;
            &lt;!-- Each annotation is placed on its own line --&gt;
            &lt;option&gt;all-open:annotation=javax.ws.rs.Path&lt;/option&gt;
        &lt;/pluginOptions&gt;
    &lt;/configuration&gt;

    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.jetbrains.kotlin&lt;/groupId&gt;
            &lt;artifactId&gt;kotlin-maven-allopen&lt;/artifactId&gt;
            &lt;version&gt;${kotlin.version}&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
&lt;/plugin&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The important thing to note is the use of the <a href="https://kotlinlang.org/docs/reference/compiler-plugins.html#all-open-compiler-plugin">all-open</a> Kotlin compiler plugin.
In order to understand why this plugin is needed, first we need to note that by default all the classes generated from the Kotlin compiler are marked as <code>final</code>.</p>
</div>
<div class="paragraph">
<p>Having <code>final</code> classes however does not work well with various frameworks that need to create <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/reflection/proxy.html">Dynamic Proxies</a>.</p>
</div>
<div class="paragraph">
<p>Thus, the <code>all-open</code> Kotlin compiler plugin allows us to configure the compiler to <strong>not</strong> mark as <code>final</code> classes that have certain annotations. In the snippet above,
we have specified that classes annotated with <code>javax.ws.rs.Path</code> should not be <code>final</code>.</p>
</div>
<div class="paragraph">
<p>If your application contains classes annotated with <code>javax.enterprise.context.ApplicationScoped</code>
for example, then <code>&lt;option&gt;all-open:annotation=javax.enterprise.context.ApplicationScoped&lt;/option&gt;</code> needs to be added as well. Same goes for any class that needs to have a dynamic proxy created at runtime.</p>
</div>
<div class="paragraph">
<p>Future versions of Quarkus will configure the Kotlin compiler plugin in a way that will make it unnecessary to alter this configuration.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="important-gradle-configuration-points"><a class="anchor" href="#important-gradle-configuration-points"></a>Important Gradle configuration points</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Similar to the Maven configuration, when using Gradle, the following modifications are required when Kotlin is selected:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>The <code>quarkus-kotlin</code> artifact is added to the dependencies. This artifact provides support for Kotlin in the live reload mode (more about this later on)</p>
</li>
<li>
<p>The <code>kotlin-stdlib-jdk8</code> is also added as a dependency.</p>
</li>
<li>
<p>The Kotlin plugin is activated, which implicitly adds <code>sourceDirectory</code> and <code>testSourceDirectory</code> build properties to point to Kotlin sources (<code>src/main/kotlin</code> and <code>src/test/kotlin</code> respectively)</p>
</li>
<li>
<p>The all-open Kotlin plugin tells the compiler not to mark as final, those classes with the annotations highlighted (customize as required)</p>
</li>
<li>
<p>When using native-image, the use of http (or https) protocol(s) must be declared</p>
</li>
<li>
<p>An example configuration follows:</p>
</li>
</ul>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="groovy" class="language-groovy hljs">plugins {
    id 'java'
    id 'io.quarkus' version '1.7.0.Final' <i class="conum" data-value="1"></i><b>(1)</b>

    id "org.jetbrains.kotlin.jvm" version "{kotlin-version}" <i class="conum" data-value="2"></i><b>(2)</b>
    id "org.jetbrains.kotlin.plugin.allopen" version "{kotlin-version}" <i class="conum" data-value="2"></i><b>(2)</b>
}

repositories {
    mavenCentral()
}

group = '...' // set your group
version = '1.0.0-SNAPSHOT'

dependencies {
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:{kotlin-version}'

    <i class="conum" data-value="3"></i><b>(3)</b>
    implementation enforcedPlatform('io.quarkus:quarkus-bom:1.7.0.Final')
    implementation 'io.quarkus:quarkus-resteasy'
    implementation 'io.quarkus:quarkus-resteasy-jsonb'
    implementation 'io.quarkus:quarkus-kotlin'

    testImplementation 'io.quarkus:quarkus-junit5'
    testImplementation 'io.rest-assured:rest-assured'
}

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

test {
    useJUnitPlatform()
    exclude '**/Native*'
}

buildNative {
    enableHttpUrlHandler = true
}

allOpen { <i class="conum" data-value="4"></i><b>(4)</b>
    annotation("javax.ws.rs.Path")
    annotation("javax.enterprise.context.ApplicationScoped")
    annotation("io.quarkus.test.junit.QuarkusTest")
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The Quarkus plugin needs to be applied.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The Kotlin plugin version needs to be specified.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>We include the Quarkus BOM using Gradle&#8217;s <a href="https://docs.gradle.org/5.4.1/userguide/managing_transitive_dependencies.html#sec:bom_import">relevant syntax</a></td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The all-open configuration required, as per Maven guide above</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>or, if you use the Gradle Kotlin DSL:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">import io.quarkus.gradle.tasks.QuarkusNative
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "..."
version = "1.0.0-SNAPSHOT"

plugins {
    java
    id("io.quarkus") version "1.7.0.Final" <i class="conum" data-value="1"></i><b>(1)</b>

    kotlin("jvm") version "{kotlin-version}" <i class="conum" data-value="2"></i><b>(2)</b>
    id("org.jetbrains.kotlin.plugin.allopen") version "{kotlin-version}" <i class="conum" data-value="2"></i><b>(2)</b>
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))

    <i class="conum" data-value="3"></i><b>(3)</b>
    implementation(enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}"))
    implementation("io.quarkus:quarkus-kotlin")
    implementation("io.quarkus:quarkus-resteasy")
    implementation("io.quarkus:quarkus-resteasy-jsonb")

    testImplementation("io.quarkus:quarkus-junit5")
    testImplementation("io.rest-assured:rest-assured")
}

tasks {
    named&lt;QuarkusNative&gt;("buildNative") {
        setEnableHttpUrlHandler(true)
    }
}

allOpen { <i class="conum" data-value="4"></i><b>(4)</b>
    annotation("javax.ws.rs.Path")
    annotation("javax.enterprise.context.ApplicationScoped")
    annotation("io.quarkus.test.junit.QuarkusTest")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
    jvmTarget = "1.8"
}

val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
    jvmTarget = "1.8"
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The Quarkus plugin needs to be applied.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The Kotlin plugin version needs to be specified.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>We include the Quarkus BOM using Gradle&#8217;s <a href="https://docs.gradle.org/5.4.1/userguide/managing_transitive_dependencies.html#sec:bom_import">relevant syntax</a></td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>The all-open configuration required, as per Maven guide above</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="cdi-inject-with-kotlin"><a class="anchor" href="#cdi-inject-with-kotlin"></a>CDI @Inject with Kotlin</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Kotlin reflection annotation processing differs from Java.  You may experience an error when using CDI @Inject such as:
"kotlin.UninitializedPropertyAccessException: lateinit property xxx has not been initialized"</p>
</div>
<div class="paragraph">
<p>In the example below, this can be easily solved by adapting the annotation, adding @field: Default, to handle the lack of a @Target on the Kotlin reflection annotation definition.</p>
</div>
<div class="paragraph">
<p>Alternatively, prefer the use of constructor injection which works without modification of the Java examples.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">import javax.inject.Inject
import javax.enterprise.inject.Default
import javax.enterprise.context.ApplicationScoped

import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType



@ApplicationScoped
class GreetingService {

    fun greeting(name: String): String {
        return "hello $name"
    }

}

@Path("/")
class GreetingResource {

    @Inject
    @field: Default <i class="conum" data-value="1"></i><b>(1)</b>
    lateinit var service: GreetingService

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/greeting/{name}")
    fun greeting(@PathParam("name") name: String): String {
        return service.greeting(name)
    }

}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Kotlin requires a @field: xxx qualifier as it has no @Target on the annotation definition. Add @field: xxx in this example. @Default is used as the qualifier, explicitly specifying the use of the default bean.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="live-reload"><a class="anchor" href="#live-reload"></a>Live reload</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Quarkus provides support for live reloading changes made to source code. This support is also available to Kotlin, meaning that developers can update their Kotlin source
code and immediately see their changes reflected.</p>
</div>
<div class="paragraph">
<p>To see this feature in action, first execute: <code>./mvnw compile quarkus:dev</code></p>
</div>
<div class="paragraph">
<p>When executing an HTTP GET request against <code><a href="http://localhost:8080/greeting" class="bare">http://localhost:8080/greeting</a></code>, you see a JSON message with the value <code>hello</code> as its <code>message</code> field.</p>
</div>
<div class="paragraph">
<p>Now using your favorite editor or IDE, update <code>GreetingResource.kt</code> and change the <code>hello</code> method to the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="kotlin" class="language-kotlin hljs">fun hello() = Greeting("hi")</code></pre>
</div>
</div>
<div class="paragraph">
<p>When you now execute an HTTP GET request against <code><a href="http://localhost:8080/greeting" class="bare">http://localhost:8080/greeting</a></code>, you should see a JSON message with the value <code>hi</code> as its <code>message</code> field.</p>
</div>
<div class="paragraph">
<p>One thing to note is that the live reload feature is not available when making changes to both Java and Kotlin source that have dependencies on each other. We hope to alleviate this limitation in the future.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="packaging-the-application"><a class="anchor" href="#packaging-the-application"></a>Packaging the application</h2>
<div class="sectionbody">
<div class="paragraph">
<p>As usual, the application can be packaged using <code>./mvnw clean package</code> and executed using the <code>-runner.jar</code> file. You can also build the native executable using <code>./mvnw package -Pnative</code>, or <code>./gradlew buildNative</code>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="kotlin-and-jackson"><a class="anchor" href="#kotlin-and-jackson"></a>Kotlin and Jackson</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If the <code>com.fasterxml.jackson.module:jackson-module-kotlin</code> dependency and the <code>quarkus-jackson</code> extension (or the <code>quarkus-resteasy-extension</code>) have been added to project,
then Quarkus automatically registers the <code>KotlinModule</code> to the <code>ObjectMapper</code> bean (see <a href="rest-json#jackson">this</a> guide for more details).</p>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
